package br.ufrn.spl.ev.models.conflictmodel;

import java.util.Map;
import java.util.TreeMap;

import br.ufrn.spl.ev.models.changeloghistorymodel.FeatureChangeLog;

/**
 * Associate a feature in source with his conflict on target.
 * 
 * @author uira
 * @author jadson
 *
 *
 * @since 05/04/2013
 * @version 1.0 - Class Creation
 */
public class ProductLineConflict {
	
	/** A feature in source that are conflicting. 
	 * 
	 * Identify the product line conflict */
	private FeatureChangeLog sourceFeature;

	/** Use a tree map instead of list to guaranteed log(n) time cost for the containsKey, get, put and remove operations.*/
	private Map<String, FeatureConflict> featureConflicts = new TreeMap<String, FeatureConflict>();
	
	public ProductLineConflict(FeatureChangeLog sourceFeature) {
		this.sourceFeature = sourceFeature;		
	}	
	
	public ProductLineConflict(FeatureChangeLog sourceFeature, TreeMap<String, FeatureConflict> featureConflicts) {
		this.sourceFeature = sourceFeature;
		this.featureConflicts = featureConflicts;
	}	
	
	public FeatureConflict createFeatureConflict(String featureName) {
		FeatureConflict featureConflict = new FeatureConflict(new FeatureChangeLog(featureName));	
		featureConflicts.put(featureName, featureConflict);
		return featureConflict;
	}
	
	
	public FeatureConflict getFeatureConflict(String featureName) {
		return featureConflicts.get(featureName);
	}
	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((sourceFeature == null) ? 0 : sourceFeature.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ProductLineConflict other = (ProductLineConflict) obj;
		if (sourceFeature == null) {
			if (other.sourceFeature != null)
				return false;
		} else if (!sourceFeature.equals(other.sourceFeature))
			return false;
		return true;
	}
	
	// setters e getters  ///
	public FeatureChangeLog getSourceFeature() {return sourceFeature;}
	public void setSourceFeature(FeatureChangeLog sourceFeature) {this.sourceFeature = sourceFeature;}
	public Map<String, FeatureConflict> getFeatureConflicts() {return featureConflicts;}
	public void setFeatureConflicts(Map<String, FeatureConflict> featureConflicts) {this.featureConflicts = featureConflicts;}
	
	
}
